@extends('admin.admin')

@section('content')
        <!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        属性值管理
        <small>分类列表</small>
        <small>分类属性值</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="/admin"><i class="fa fa-dashboard"></i> 控制面板</a></li>
        <li ><a href="/admin/category">分类管理</a></li>
        <li ><a href="/admin/category/category_attribute/{{$cat_id}}">属性管理</a></li>
        <li ><a href="/admin/category_attribute/category_attribute_value?cat_id={{$cat_id}}&category_attribute_id={{$category_attribute_id}}">属性值管理</a></li>
        <li>属性值列表</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">

    <div class="row">
        <div class="col-xs-12">
            <div class="box box-primary">
                <div class="box-header">
                    <h3 class="box-title">属性值列表</h3>
                    <div class="pull-right">

                        <a href="/admin/category_attribute_value/create?cat_id={{$cat_id}}&category_attribute_id={{$category_attribute_id}}" type="button" style="display:inline;" class="btn btn-block btn-success btn-xs">
                            <i class="icon  glyphicon glyphicon-plus"></i>
                            添加</a>
                        <a href="{{route('admin.category.categoryAttribute',$cat_id)}}" type="button" style="display:inline;" class="btn btn-block btn-success btn-xs">
                            <i class="icon  glyphicon glyphicon glyphicon-menu-left"></i>
                            返回</a>

                    </div>
                </div>
                <!-- /.box-header -->
                <div class="box-body table-responsive no-padding">
                {!! Form::hidden('_method', 'POST') !!}
                {!! Form::hidden('url',@$_SERVER["REQUEST_URI"]) !!}
                    <table class="table table-hover">
                        <tr>
                            <th>ID</th>
                            <th style="min-width: 200px;">属性值名称</th>
                            <th style="width: 250px;">操作</th>
                        </tr>
                        <?php //dd($categoryBrands);?>
                        @foreach ($categoryAttributeValue as $attributeValue)
                            <tr>
                                <td>{{$attributeValue->id}}</td>
                                <td class="J-name">{{$attributeValue->attribute_value}}</td>
                                <td>
                                <a type="button" class="btn  btn-update btn-xs" data-id="{{$attributeValue->id}}"><i class="icon  glyphicon glyphicon-edit"></i> 修改</a>
                                <button type="button" class="btn  btn-danger btn-xs" data-toggle="modal" data-target="#modal{{$attributeValue->id}}">
                                        <i class="icon  glyphicon glyphicon-remove"></i> 删除
                                </button>

                                <div id="modal{{$attributeValue->id}}" class="modal fade">
                                    <div class="modal-dialog">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal"
                                                        aria-label="Close"><span aria-hidden="true">&times;</span>
                                                </button>
                                                <h4 class="modal-title">删除警告:</h4>
                                            </div>
                                            <div class="modal-body">
                                                <p>确认要删除属性值[{{$attributeValue->attribute_value}}]吗?</p>
                                            </div>
                                            <div class="modal-footer">

                                                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                                <button type="submit" class="btn btn-danger01" item_cat_id="{{$cat_id}}" item_category_attribute_id="{{$category_attribute_id}}" itemid="{{$attributeValue->id}}">删除</button>

                                            </div>
                                        </div><!-- /.modal-content -->
                                    </div><!-- /.modal-dialog -->
                                </div><!-- /.modal -->

                                </td>
                            </tr>
                        @endforeach

                    </table>
                </div>
                <!-- /.box-body -->
                <div class="box-footer">
                                    <!-- 分页 -->
                    <div class="pull-right no-margin-pager">
                        {!! $categoryAttributeValue->appends(['id'=>$category_attribute_id])->render() !!}
                    </div>
                </div>
            </div>
            <!-- /.box -->
        </div>
    </div>


<div id="editModal" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">编辑</h4>
            </div>
            <div class="modal-body">
                <div class="form-group">
                  <label class="control-label">属性值:</label>
                  <input type="text" class="form-control name" name="name">
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="J-ok btn btn-success" >确定</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>
</section>

<!-- /.content -->
<script>
    $('.btn-danger').on('click', function () {
        console.log('11');
    });
</script>

<script>
var editModal=$('#editModal');
$('.btn-update').on('click',function(e){
    var that=$(this),
        id=that.data('id'),
        nameTd=that.closest('td').siblings('.J-name');
    editModal.find('.name').val(nameTd.text());
    editModal.data('id',id);
    editModal.modal();
});
editModal.on('click','.J-ok',function(){
    var name=editModal.find('.name').val();
    var id=editModal.data('id');
    var td=editModal.data('td');
    console.log(name);
    $.ajax({
        url:'/admin/category_attribute_value/update/'+id+"?"+Math.random(),
        dataType:'json',
        type:'post',
        data:{attribute_value:name,id:id},
        success:function(res){
            console.log(res.status);
            editModal.modal('hide');
            if(res.status){
                window.location.reload();
            }else if(res.status==0&&res.message){
                alert(res.message);
            }
        }
    });
});
</script>

<script>
        $('.btn-danger01').on('click',function(e){
            e.preventDefault();
            var id = $(this).attr("itemid"),cat_id = $(this).attr("item_cat_id"),category_attribute_id = $(this).attr("item_category_attribute_id");
            if(!id) return false;
            $.ajax({
                url:'/admin/categoryAttribute/delCategoryAttributeValue/'+id+"?"+Math.random(),
                type:'delete',
                data:{id:id,cat_id:cat_id,category_attribute_id:category_attribute_id,'_token':'{{csrf_token()}}'},
                dataType:"json",
                success:function(result){

                    if(result.status==1){
                        $('#del_alert').modal();
                        $("#ok").hide();
                        $("#no").show();
                        $("#message_content").html(result.info);
                        window.location.reload();
                    }else{
                        alert(result.message);
                        window.location.reload();
                    }

                }

            });

        });
</script>
@endsection